package com.wb.base;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import java.util.List;

public class TabAdapter extends PagerAdapter {

    private List<BaseTabView> mViewList;

    public TabAdapter(List<BaseTabView> listViews) {
        this.mViewList = listViews;
    }


    @Override
    public void destroyItem(View container, int position, Object object) {
        View view = mViewList.get(position % mViewList.size()).getRootView();
        ((ViewPager) container).removeView(view);
    }

    @Override
    public Object instantiateItem(View container, int position) {
        View view = mViewList.get(position % mViewList.size()).getRootView();
        ((ViewPager) container).addView(view);
        return view;
    }

    @Override
    public int getCount() {
        return mViewList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mViewList.get(position).getTabTitle();
    }
}
